package com.yaozheng.vocationaltraining.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.BaseActivity;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.adapter.PaperQuestionListAdapter;
import com.yaozheng.vocationaltraining.fragment.ItemQuestionFragment;
import com.yaozheng.vocationaltraining.fragment.ItemQuestionFragment_;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

@EViewGroup(R.layout.view_paper_question_list)
public class PaperQuestionListView extends LinearLayout {
	@ViewById
	ViewPager viewPager;

	public PaperQuestionListView(Context context, AttributeSet attrs,
			int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
	}

	public PaperQuestionListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public PaperQuestionListView(Context context) {
		super(context);
	}

	/**
	 * 初始化View
	 */
	@AfterViews
	public void initView() { // viewPager.setOffscreenPageLimit(3);

		viewPager.setAdapter(new PagerAdapter() {

			@Override
			public void destroyItem(ViewGroup container, int position,
					Object object) {
				container.removeView((View) object);
			}

			@Override
			public int getItemPosition(Object object) {
				return POSITION_NONE;
			}

			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				return arg0 == arg1;
			}

			@Override
			public Object instantiateItem(ViewGroup container, int position) { // 这个方法用来实例化页卡
				ItemQuestionView itemQuestionView = ItemQuestionView_
						.build(getContext());
				// itemQuestionView.loadData(position);
				container.addView(itemQuestionView);// 添加页卡
				return itemQuestionView;
			}

			@Override
			public int getCount() {
				return 3;
			}
		});
		// );new PaperQuestionListAdapter(fragmentManager));
	}

	/**
	 * 初始化
	 */
	public void onFinishInflate() {
		super.onFinishInflate();
	}

}
